package com.hm.email.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.hm.common.annotation.AuthenticationAnnotation;
import com.hm.common.annotation.RequestPlanAnnotation;
import com.hm.common.model.BaseController;
import com.hm.common.model.ControllerResult;
import com.hm.email.mongo.domain.def.EmailTypeDef;
import com.hm.email.share.service.SendEmailService;
import com.hm.email.util.EmailConfigDef;
import com.hm.email.vo.EmailVo;

import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

/**
 * @author shishun.wang
 * @date 下午5:34:44 2016年6月16日
 * @version 1.0
 * @describe
 */
@ResponseBody
@RestController
@RequestMapping(value = EmailConfigDef.Api.Rest.Email.REST_EMAIL)
public class SendEmailController extends BaseController {

	public static final String swaggerTag = "邮箱管理";

	@Autowired
	private SendEmailService sendEmailService;

	@AuthenticationAnnotation
	@RequestMapping(value = "/{emailType}", method = RequestMethod.POST)
	@ApiOperation(value = "发送邮件", httpMethod = "POST", notes = "发送邮件返回本次发送邮件的数据记录编号ID", tags = swaggerTag)
	@RequestPlanAnnotation(title = "发送邮件", content = "发送邮件返回本次发送邮件的数据记录编号ID")
	public ResponseEntity<ControllerResult<String>> sendEmail(
			@ApiParam(required = true, name = "emailType", value = "邮件类型") @PathVariable("emailType") EmailTypeDef emailType,
			@ApiParam(required = true, name = "body", value = "邮件基本信息") @RequestBody(required = true) EmailVo emailModel) {
		try {
			return ControllerResult.success(sendEmailService.send(emailModel, emailType, currentUserId()), "发送成功");
		} catch (Exception e) {
			return ControllerResult.failed(e);
		}
	}
}
